const sequelize = require("../app/db");
const { DataTypes, Model } = require("sequelize");

class Blog extends Model {}
Blog.init(
  {
    Id: {
      type: DataTypes.INTEGER,
      allowNull: false, //不允许为空
      primaryKey: true,
      autoIncrement: true,
    },
    Title: {
      type: DataTypes.STRING,
    },
    ImgUrl: {
      type: DataTypes.STRING,
    },
    UserId: {
      type: DataTypes.INTEGER,
    },
    Content: {
      type: DataTypes.TEXT,
    },
    Tags: {
      type: DataTypes.STRING,
    },
    Description: {
      type: DataTypes.STRING,
    },
    Status: {
      type: DataTypes.INTEGER,
    },
    CreateTime: {
      type: DataTypes.STRING,
      get() {
        return new Date(this.getDataValue("CreateTime")).getTime();
      },
    },
    ModifyTime: {
      type: DataTypes.STRING,
      get() {
        return new Date(this.getDataValue("ModifyTime")).getTime();
      },
    },
  },
  {
    sequelize,
    modelName: "Blog",
    tableName: "blog", //强制设置表名
  }
);

module.exports = Blog;
